﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 花店管理系统.geren
{
    public partial class Sonlizhinan : Form
    {
        public Sonlizhinan()
        {
            InitializeComponent();
        }
        void ShowALLProduct()
        {
            DB.GetCn();
            String str = "select * from Tgood";
            SqlCommand cmd = new SqlCommand(str, DB.cn);
            SqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                int index = dgvHua.Rows.Add();
                dgvHua.Rows[index].Cells[0].Value = rdr[0];
                dgvHua.Rows[index].Cells[1].Value = rdr[1];
                dgvHua.Rows[index].Cells[2].Value = rdr[3];
                dgvHua.Rows[index].Cells[3].Value = rdr[9];
                dgvHua.Rows[index].Cells[4].Value = rdr[10];
                dgvHua.Rows[index].Cells[5].Value = rdr[12];
                dgvHua.Rows[index].Cells[6].Value = rdr[13];

                try
                {
                    Image imageColum = Image.FromFile(Application.StartupPath + rdr[11]);
                    dgvHua.Rows[index].Cells["Column6"].Value = imageColum;
                }
                catch
                {
                    Image imageColum = Image.FromFile(Application.StartupPath + "\\" + "暂无图片.png");
                    dgvHua.Rows[index].Cells["Column6"].Value = imageColum;
                }
            }
            rdr.Close();
        }

        private void btnSecah_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("请输入查询关键字");

            }
            else
            {
                dgvHua.Rows.Clear();
                DB.GetCn();
                SqlDataReader rdr = Shousuo();
                while (rdr.Read())
                {
                    int index = dgvHua.Rows.Add();
                    dgvHua.Rows[index].Cells[0].Value = rdr[0];
                    dgvHua.Rows[index].Cells[1].Value = rdr[1];
                    dgvHua.Rows[index].Cells[2].Value = rdr[3];
                    dgvHua.Rows[index].Cells[3].Value = rdr[9];
                    dgvHua.Rows[index].Cells[4].Value = rdr[10];
                    dgvHua.Rows[index].Cells[5].Value = rdr[12];
                    dgvHua.Rows[index].Cells[6].Value = rdr[13];
                    try
                    {
                        Image imageColum = Image.FromFile(Application.StartupPath + rdr[11]);
                        dgvHua.Rows[index].Cells["Column6"].Value = imageColum;
                    }
                    catch
                    {
                        Image imageColum = Image.FromFile(Application.StartupPath + "\\" + "暂无图片.png");
                        dgvHua.Rows[index].Cells["Column6"].Value = imageColum;
                    }
                }
                rdr.Close();
            }

            SqlDataReader Shousuo()
            {
                string str = "select * from Tgood where G_duixiang like '%" + textBox1.Text + "%'";
                SqlCommand cmd = new SqlCommand(str, DB.cn);
                SqlDataReader rdr = cmd.ExecuteReader();
                return rdr;
            }
        }

        private void Sonlizhinan_Load(object sender, EventArgs e)
        {
            dgvHua.RowTemplate.Height = 90;
            dgvHua.Columns[0].Width = 80;
            dgvHua.Columns[1].Width = 80;
            dgvHua.Columns[2].Width = 80;
            dgvHua.Columns[3].Width = 100;
            dgvHua.Columns[4].Width = 100;
            dgvHua.Columns[5].Width = 100;
            dgvHua.Columns[6].Width = 100;
            dgvHua.Columns[7].Width = 100;
            ShowALLProduct();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnSecah2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                MessageBox.Show("请输入查询关键字");

            }
            else
            {
                dgvHua.Rows.Clear();
                DB.GetCn();
                SqlDataReader rdr = Changjing();
                while (rdr.Read())
                {
                    int index = dgvHua.Rows.Add();
                    dgvHua.Rows[index].Cells[0].Value = rdr[0];
                    dgvHua.Rows[index].Cells[1].Value = rdr[1];
                    dgvHua.Rows[index].Cells[2].Value = rdr[3];
                    dgvHua.Rows[index].Cells[3].Value = rdr[9];
                    dgvHua.Rows[index].Cells[4].Value = rdr[10];
                    dgvHua.Rows[index].Cells[5].Value = rdr[12];
                    dgvHua.Rows[index].Cells[6].Value = rdr[13];
                    try
                    {
                        Image imageColum = Image.FromFile(Application.StartupPath + rdr[11]);
                        dgvHua.Rows[index].Cells["Column6"].Value = imageColum;
                    }
                    catch
                    {
                        Image imageColum = Image.FromFile(Application.StartupPath + "\\" + "暂无图片.png");
                        dgvHua.Rows[index].Cells["Column6"].Value = imageColum;
                    }
                }
                rdr.Close();
            }

            SqlDataReader Changjing()
            {
                string str = "select * from Tgood where G_changjing like '%" + textBox2.Text + "%'";
                SqlCommand cmd = new SqlCommand(str, DB.cn);
                SqlDataReader rdr = cmd.ExecuteReader();
                return rdr;
            }
        }

        private void btnShowAll_Click(object sender, EventArgs e)
        {
            dgvHua.Rows.Clear();
            ShowALLProduct();
        }

        private void btnCanle_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
